package com.ruoyi.order.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.mapper.ProductionOperationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.order.mapper.OrderFulfillmentMapper;
import com.ruoyi.order.domain.OrderFulfillment;
import com.ruoyi.order.service.IOrderFulfillmentService;

/**
 * 订单任务执行Service业务层处理
 *
 * @author testlove
 * @date 2021-07-08
 */
@Service
public class OrderFulfillmentServiceImpl implements IOrderFulfillmentService
{
    @Autowired
    private OrderFulfillmentMapper orderFulfillmentMapper;
    @Autowired
    private ProductionOperationMapper productionOperationMapper;

    /**
     * 查询订单任务执行
     *
     * @param orderFulfillmentId 订单任务执行ID
     * @return 订单任务执行
     */
    @Override
    public OrderFulfillment selectOrderFulfillmentById(Long orderFulfillmentId)
    {
        OrderFulfillment orderFulfillment = orderFulfillmentMapper.selectOrderFulfillmentById(orderFulfillmentId);
        return orderFulfillment;
    }

    /**
     * 查询订单任务执行列表
     *
     * @param orderFulfillment 订单任务执行
     * @return 订单任务执行
     */
    @Override
    public List<OrderFulfillment> selectOrderFulfillmentList(OrderFulfillment orderFulfillment)
    {
        List<OrderFulfillment> orderFulfillments = orderFulfillmentMapper.selectOrderFulfillmentList(orderFulfillment);
        for (OrderFulfillment orderFulfillment1 :
                orderFulfillments) {
            orderFulfillment1.setOperation(productionOperationMapper.selectProductionOperationById(orderFulfillment1.getOperationId()).getOperationName());
        }

        return orderFulfillments;
    }

    /**
     * 新增订单任务执行
     *
     * @param orderFulfillment 订单任务执行
     * @return 结果
     */
    @Override
    public int insertOrderFulfillment(OrderFulfillment orderFulfillment)
    {
        orderFulfillment.setCreateTime(DateUtils.getNowDate());
        return orderFulfillmentMapper.insertOrderFulfillment(orderFulfillment);
    }

    /**
     * 修改订单任务执行
     *
     * @param orderFulfillment 订单任务执行
     * @return 结果
     */
    @Override
    public int updateOrderFulfillment(OrderFulfillment orderFulfillment)
    {
        orderFulfillment.setUpdateTime(DateUtils.getNowDate());
        return orderFulfillmentMapper.updateOrderFulfillment(orderFulfillment);
    }

    /**
     * 批量删除订单任务执行
     *
     * @param orderFulfillmentIds 需要删除的订单任务执行ID
     * @return 结果
     */
    @Override
    public int deleteOrderFulfillmentByIds(Long[] orderFulfillmentIds)
    {
        return orderFulfillmentMapper.deleteOrderFulfillmentByIds(orderFulfillmentIds);
    }

    /**
     * 删除订单任务执行信息
     *
     * @param orderFulfillmentId 订单任务执行ID
     * @return 结果
     */
    @Override
    public int deleteOrderFulfillmentById(Long orderFulfillmentId)
    {
        return orderFulfillmentMapper.deleteOrderFulfillmentById(orderFulfillmentId);
    }
}
